/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-12-16     RT-Thread    first version
 * 2025-05-14     Trae AI      add thread management
 */

#ifndef __THREAD_MANAGE_H__
#define __THREAD_MANAGE_H__

#include <rtthread.h>
#include "mpu6xxx.h"

/* 线程栈大小定义 */
#define SENSOR_THREAD_STACK_SIZE        1024
#define DATA_PROCESS_THREAD_STACK_SIZE  2048

/* 线程优先级定义 */
#define SENSOR_THREAD_PRIORITY          10
#define DATA_PROCESS_THREAD_PRIORITY    11

/* 线程时间片定义 */
#define SENSOR_THREAD_TIMESLICE         10
#define DATA_PROCESS_THREAD_TIMESLICE   10

/* 消息队列大小定义 */
#define SENSOR_DATA_MQ_SIZE             10

/* 定时器周期定义（ms） */
#define REPORT_TIMER_PERIOD             (30 * 1000)  /* 30秒 */

/* 事件标志定义 */
#define EVENT_UART_ERROR                (1 << 0)
#define EVENT_WINDOW_COMPLETE           (1 << 1)
#define EVENT_REPORT_NEEDED             (1 << 2)

/* 采样参数定义 */
#define WINDOW_SIZE                     128     /* 数据窗口大小，与Python接收端匹配 */
#define SAMPLE_INTERVAL                 50      /* 采样间隔(ms) */

/* 传感器数据消息结构体 */
struct sensor_data_msg
{
    struct mpu6xxx_3axes accel;
    struct mpu6xxx_3axes gyro;
};

/* 函数声明 */
rt_err_t har_thread_init(rt_device_t uart_dev, struct mpu6xxx_device *sensor_dev);
void har_event_handler(void);

#endif /* __THREAD_MANAGE_H__ */